﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace CustomControlLibrary
{
    public class AlarmClock: Clock
    {

        public AlarmClock():base()
        {
        }

        public bool AlarmSet
        {
            get
            {
                return (bool)GetValue(AlarmSetProperty);
            }
            set
            {
                this.SetValue(AlarmSetProperty, value);
            }
        }


        public static DependencyProperty AlarmSetProperty = DependencyProperty.Register(
            "AlarmSet",
            typeof(bool),
            typeof(AlarmClock),
            new PropertyMetadata(false, new PropertyChangedCallback(OnStartTimeInvalidated)));


        public DateTime StartTime
        {
            get { return (DateTime)GetValue(StartTimeProperty); }
            set 
            {
                this.AlarmSet = value > DateTime.Now && value < DateTime.Now.AddDays(1);
                SetValue(StartTimeProperty, value); 
            }
        }

        public static DependencyProperty StartTimeProperty = DependencyProperty.Register(
            "StartTime",
            typeof(DateTime),
            typeof(AlarmClock),
            new PropertyMetadata(DateTime.Now.AddHours(7), new PropertyChangedCallback(OnStartTimeInvalidated)));

        public static readonly RoutedEvent StartTimeChangedEvent =
            EventManager.RegisterRoutedEvent("StartTimeChangedEvent", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventArgs<DateTime>), typeof(AlarmClock));

        protected virtual void OnStartTimeChanged(DateTime oldValue, DateTime newValue)
        {
            RoutedPropertyChangedEventArgs<DateTime> args = new RoutedPropertyChangedEventArgs<DateTime>(oldValue, newValue);
            args.RoutedEvent = AlarmClock.StartTimeChangedEvent;
            RaiseEvent(args);
        }

        private static void OnStartTimeInvalidated(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            AlarmClock clock = (AlarmClock)d;
        }
    }
}
